package momo.multitree.structure;

/**
 * Specialized datastore for latency calculations
 * 
 * given a pair of nodes, stores latency between them
 * 
 * besides, stores the maximum and the second maximum latency in the graph
 * @author krz
 *
 */
public class LatencyPair extends NodePair
{
	private Node maxNode;
	private double[] maxLatency;
	
	public LatencyPair()
	{
		super();
		maxLatency = new double[2];
	}
	
	public void setMaxLat(Node node, double currLat)
	{
		double tmpMax = 0;
		
		if ( currLat > maxLatency[0] )
		{
			tmpMax = maxLatency[0];
			maxLatency[0] = currLat;
			maxNode = node;
		}else
			tmpMax = currLat;
		
		maxLatency[1] = Math.max(tmpMax, maxLatency[1]);
	}
	
	/**
	 * Returns the maximum latency; or, if node is equal 
	 * to the node for which the latency is maximal, returns 
	 * the second-maximal latency
	 * 
	 * @param node
	 * @return
	 */
	public double getMaxLat(Node node)
	{
		// Commented as changes made in journal paper
		// now max late of same node is taking into consideration
//		if ( node == maxNode )
//			return maxLatency[1];
		return maxLatency[0];
	}
}
